<?php
require_once "../class/fenajax.class.php";
include "../dyn/connexion.php";

$f = new fenAjax("Formulaire Actualite",0);

if(isset($_POST['mode']) and isset($_POST['id_actu']) and isset($_POST['titre']) and isset($_POST['contenu']) and isset($_POST['date'])) {
	
	$mode = $_POST['mode'];
	$id_actu = $_POST['id_actu'];
	$titre = $_POST['titre'];
	$contenu = $_POST['contenu'];
	$date = $_POST['date'];
	
	
	if( !in_array($mode,array(1,2)))
		$f->ajaxErreur("Fonction non supportée","Ce mode n'est pas supporté pour ce module");
		
	if($mode == 1){		$header = "Ajouter une actualité"; 		$nomAction = "Ajouter";		$disable = ""; }
	if($mode == 2){		$header = "Supprimer une actualité"; 	$nomAction = "Supprimer";	$disable = ""; }
		
	$f->retourAjax["boutton"] = $nomAction;
	$f->retourAjax["header"] = $header;
	
	$form = "<div id=\"feedback\"></div><br />";
	
	$form .= "<form action=\"#\" method=\"post\" onSubmit=\"return actionActualite($(this));\">";
	
	
	if ($mode == 1) {
	
		$form .= " <script type=\"text/javascript\">
				init_editeur();
				</script>
		";
	
		$form .= "<div class=\"center\">
				<br /><label for=\"titre\">Titre :</label><br />	
				<input class=\"ui-corner-all\" id=\"titre\" type=\"text\" value=\"".s($titre)."\" name=\"titre\" $disable/><br />
				</div>
		";
		
		$form .= "<div class=\"center\">
						<br /><label for=\"contenu\">Contenu :</label><br />
					</div>
					<div class=\"editeur\">
						<textarea id=\"afficheEditeur\" name=\"contenu\" ></textarea>
					</div><br />
					
		";
		
		$form .= "<input type=\"hidden\" name=\"id_actu\" value=\"".$id_actu."\" />";
		$form .= "<input type=\"hidden\" name=\"date\" value=\"".$date."\" />";	
	
	}
	
	if($mode == 2) {
							
		$res = mysql_query("SELECT * FROM Actualite ORDER BY date;");
		
		if (mysql_num_rows($res) != 0) {
			
			$form .= "<br /><label class=\"formInfos\" for=\"id_actu\">Actualité :</label>
					<select id=\"id_actu\" name=\"id_actu\" $disable>
			";
			
			$prems = true;
			
			while($row = mysql_fetch_array($res)) {
				$form .= "<option value=\"".$row['id']."\" ".($prems ? "selected=\"selected\"":"").">".$row['titre']."</option>";
				$prems = false;
			}
			
			$form .= "</select>";
			
		}
		else {
			
			$form .= "<div class=\"center\">
						".BMInfo("Note: Il n'y a aucune actualite de créer",false)."
					</div>
			";
			
			$form .= " <input type=\"hidden\" name=\"id_actu\" value=\"".$id_actu."\" />
			";

		}
		
		$form .= " <input type=\"hidden\" name=\"titre\" value=\"".$titre."\" />
					<input type=\"hidden\" name=\"contenu\" value=\"".$contenu."\" />
					<input type=\"hidden\" name=\"date\" value=\"".$date."\" />
		";
		
	}
	
	
	
	$form .= "<input type=\"hidden\" name=\"mode\" value=\"".$mode."\" />";
	
	$f->retourAjax["erreur"] = false;
	$f->retourAjax["msg"] = $form;
}

$f->endAjax();
?>